package com.atguigu.gulimall.search.controller;

import com.atguigu.common.exception.BizCodeEnum;
import com.atguigu.common.to.elastic.SkuElasticModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author LiDeJie
 * @Create 2024/1/1 17:23
 * @Version 1.0
 */
@RestController
@RequestMapping("/search/save")
public class ElasticController {
    
    @Autowired
    ProductSaveService productSaveService;
    
    /**
     * 商品上架
     * /search/save/product
     */
    @PostMapping("/product")
    public R saveProduct(@RequestBody List<SkuElasticModel> skuElasticModelList) {
        boolean isFlag = productSaveService.productUpperStatus(skuElasticModelList);
        if (!isFlag) {
            return R.ok();
        }else {
            return R.error(BizCodeEnum.PRODUCT_UPPER.getCode(), BizCodeEnum.PRODUCT_UPPER.getMsg());
        }
    }
}
